<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags"%>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<!DOCTYPE html>
<html lang="en">
<head>
<title>开票申请</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1" />

<link rel="icon" href="favicon.ico" type="image/x-icon" />
<!-- END META SECTION -->

<!-- CSS INCLUDE -->        
      
<link rel="stylesheet" href="${ctx}/rs/css/bootstrap-table.css" />
<link rel="stylesheet" href="${ctx}/rs/css/main.css" />
<link id="theme" rel="stylesheet" href="${ctx}/rs/joli/css/theme-default.css" />

<!-- EOF CSS INCLUDE -->        
</head>
<body >

     <!-- START PAGE CONTAINER -->
      <div class="page-container">
        <!-- 引入左菜单部分 -->
          <jsp:include page="../joli/menu.jsp"></jsp:include>
          
          <!-- START PAGE CONTENT -->
          <div class="page-content">
              <jsp:include page="../joli/top.jsp"></jsp:include>
              
              <!-- START BREADCRUMB -->
              <ul class="breadcrumb">
                  <li><a href="#">开票管理</a></li>                    
                  <li class="active">开票申请</li>
              </ul>
              <!-- END BREADCRUMB -->   
              
              
              <!-- PAGE CONTENT WRAPPER -->
              <div class="page-content-wrap">
                <div class="row">
                    <div class="col-xs-12">
						<div id="toolbar">
							<div class="fr pb10">
								客户名称：<input type="text" class="srt-put1 mr10 widput1"
									id="username" name="username" />
								<button class="btn btn-primary btn-sm srt-btn active"
									onclick="refresh()">搜索</button>
							</div>
						</div>
						<table id="table" cellpadding="0" cellspacing="0" data-toggle="table" data-toolbar="#toolbar"
                            data-url="${ctx}/billing/applyList.htm"
                            data-cache="false"
                            data-pagination="true" 
                            data-side-pagination="server"
                            data-page-list="[10, 20, 50, 100]"
                            data-page-size="20"  
                            data-query-params="queryParams">
                            <thead>
                                <tr class="tab-th">
                                    <th data-field="billintId">编号</th>
                                    <th data-field="type" class="col-md-1" data-formatter="positionFormatter">客户类型</th>
                                    <th data-field="username" class="col-md-2">客户名称</th>
                                    <th data-field="billinGmoney" class="col-md-2" >开票金额（元）</th>
                                    <th data-field="billingType" class="col-md-2" data-formatter="billingTypeFormatter">发票类型</th>
                                    <th data-field="createTime" class="col-md-2" data-formatter="timeFormatter">开票申请日期</th>
                                    <th data-field="action" class="col-md-3" data-formatter="actionFormatter">操作</th>
                                </tr>
                            </thead>
                        </table>
                </div>
              </div>  
         </div>
     </div>
          <!-- 引入所有joli的脚本 -->
    <jsp:include page="../joli/scripts.jsp"></jsp:include>
    <!-- 引入页面需要的脚本 -->
    <script type="text/javascript" src="${ctx}/rs/js/bootstrapQ.min.js"></script>
    <script src="${ctx}/rs/js/bootstrap-table.js"></script>
    <script src="${ctx}/rs/js/bootstrap-table-zh-CN.js"></script>
    <script src="${ctx}/rs/js/jquery.formatDate.js"></script>
    <script src="${ctx}/rs/js/my97DatePicker/WdatePicker.js"></script>
    <script type="text/javascript" src="${ctx}/rs/js/session-out-error.js"></script>
    <script type="text/javascript">
    activeMenu($("#menu_billing_0"));
    var $table = $('#table');
    
    $table.on('click-row.bs.table', function (e, row, $element) {
          $table.bootstrapTable('uncheckAll');
          $table.bootstrapTable('check', $element.index());
    });
    
    $table.bootstrapTable({
        height: getHeight()
    });
      
    //获取分辨率高度
      function getHeight() {
          return window.screen.height - 308;
      }
      
      $(window).resize(function () {
      $table.bootstrapTable('resetView',{height: getHeight()});
    });
      
    //初始化刷新
   function refresh(pageIndex,selectPage){
        if(!pageIndex && !selectPage){
            pageIndex = 0;
            selectPage = 0;
        }
        var username = encodeURIComponent($("#username").val());
        var pageSize = $table.bootstrapTable('getOptions').pageSize;
        pageIndex=pageIndex*pageSize;
        $table.bootstrapTable('refresh', {
            silent: true,
            cache : false,
            url: '${ctx}/billing/applyList.htm',
            query: {
            	username:username,
                pageIndex : pageIndex,
                pageSize : pageSize
            }
        });
        $table.bootstrapTable('selectPage', selectPage);
    }
   function queryParams(params) {
	   var username = $("#username").val();
	   return {
    	   username : username,
    	   pageIndex : params.offset,
           pageSize : params.limit
       };
   }
    function timeFormatter(value, row, index){
         if(value){
             return $.formatDate("yyyy-MM-dd HH:mm:ss", new Date(value));
         }
         return "--";
    }
    function actionFormatter(value, row, index){
        var retbak="";
        retbak='<a class="mr15" href="javascript:billingDetail('+row.billintId+')">开票详情</a><a class="mr15" href="javascript:openBilling('+row.billintId+')">已开票</a><a class="mr15" href="javascript:noBilling('+row.billintId+')">不予开票</a>';
        return retbak;
    }
    function positionFormatter(value, row, index){
        var retbak="";
        switch(row.type){
        case '1':
            retbak="<sapn class='label label-info'>代理商</span>";
            break;
        case '0':
            retbak="<span class='label label-info'>广告主</span>";
            break;
        }
        return retbak;
    }
  //查看详情
    function billingDetail(billintId) {
             bootstrapQ.dialog({
                 url : "${ctx}/billing/detail.htm?billintId="+ billintId,
                 title : "开票详情",
                 width: '550px',
                 close : 'true',
                 hidebtn : 'true'
             },function(){
                 //回调触发关闭窗口
                 $("#bsmodal").modal("hide");
             });
     }
  //已开票
    function openBilling(billintId) {
             bootstrapQ.dialog({
                 url : "${ctx}/billing/openBilling.htm?billintId="+ billintId,
                 title : "请填写物流信息",
                 width: '400px',
                 close : 'true',
                 hidebtn : 'true'
             },function(){
                 //回调触发关闭窗口
                 $("#bsmodal").modal("hide");
                 refresh();
             });
     }
    //不予开票
    function noBilling(billintId){
    	 bootstrapQ.dialog({
             url : "${ctx}/billing/noBilling.htm?billintId="+ billintId,
             title : "请填写不予开票缘由",
             width: '400px',
             close : 'true',
             hidebtn : 'true'
         },function(){
             //回调触发关闭窗口
             $("#bsmodal").modal("hide");
             refresh();
         });
    }
    </script>
  </body >
</html>
